/**
 * Created by scenic on 2017/7/15.
 */

var start, scene, spaceRoot;
;

var BusinessTestUtils = {

    getStart: function () {
        if (start) {
            start.dispose();
        }

        document.getElementById("main_test").style.display = "block";
        var container = document.getElementById("container");
        var canvas = document.getElementById("rd_three");
        start = new GSThree.StartNB({canvas: canvas, container: container});
        return start;
    },

    getScene: function () {
        if (scene) {
            return scene;
        }
        scene = this.getStart().newScene("main");
        scene.sceneColor = "#000000"
        new GSThree.LightConfig(scene).addAmbientLight().addDirectionLight();

        function refresh() {
            requestAnimationFrame(refresh);
            start.clearCanvas();
            start.renderMultipleScene();
        }

        refresh();

        return scene;
    },
    addToScene: function (space) {


        space = space == undefined ? spaceRoot : space;

        if (scene == undefined) {
            this.getScene();
        }
        //增加mesh
        space.traverse(function () {
            if (this.spaceMesh.isAddToScene)
                scene.add(this.spaceMesh)
            this.faces.forEach(function (face) {
                if (face.getAssociateMesh().isAddToScene)
                    scene.add(face.getAssociateMesh())
            })

            // this.updateSpaceMeshMaterial();

        })

        GSThree.Utils.showSceneResource(scene, 'resource');
    },
    hideAllFrontPlank: function () {
        spaceRoot.traverse(function () {
            this.frontFace.getAssociateMesh().visible = false;
        })
    },

    showSpaceWithLine: function () {
        spaceRoot.traverse(function () {
            GSThree.Utils.transparentMesh(this.getAssociateMesh(), true);
        })
    }
};


describe("Space", function () {

    var gsbuild = GSResource;

    it("toTreeFolder", function () {
        var space = new GSResource.BoxSpace(1400, 900, 500);
        space.setSegment("1:1:1", new THREE.Vector3(1, 0, 0));
        space.updateSegment();

        space.toTreeFolder().traverse(function (f) {
            console.log(f.id);
        })
        console.log("================")
        space.toTreeFolder().traverse(function (f) {
            console.log(f.id);
        })

        expect(1).toBe(1);
    })


    it("updatePlankByBaseGraphic", function () {
        var space = new gsbuild.BoxSpace(1400, 900, 500);
        space.updateSpaceMeshAndFaces();


        var scene = BusinessTestUtils.getScene();
        space.addMeshToScene(scene);

        space.faces.forEach(function (f) {
            scene.add(f.getAssociateMesh());
            f.updatePlankByBaseGraphic();
        })


        GSThree.Utils.showSceneResource(scene,'resource');

        expect(1).toBe(1);
    })

})